<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE Unsafe #-}</span><span>
</span><span id="line-2"></span><span class="hs-pragma">{-# LANGUAGE NoImplicitPrelude, MagicHash, UnboxedTuples #-}</span><span>
</span><span id="line-3"></span><span class="hs-pragma">{-# OPTIONS_HADDOCK not-home #-}</span><span>
</span><span id="line-4"></span><span>
</span><span id="line-5"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-6"></span><span class="hs-comment">-- |</span><span>
</span><span id="line-7"></span><span class="hs-comment">-- Module      :  GHC.STRef</span><span>
</span><span id="line-8"></span><span class="hs-comment">-- Copyright   :  (c) The University of Glasgow, 1994-2002</span><span>
</span><span id="line-9"></span><span class="hs-comment">-- License     :  see libraries/base/LICENSE</span><span>
</span><span id="line-10"></span><span class="hs-comment">--</span><span>
</span><span id="line-11"></span><span class="hs-comment">-- Maintainer  :  cvs-ghc@haskell.org</span><span>
</span><span id="line-12"></span><span class="hs-comment">-- Stability   :  internal</span><span>
</span><span id="line-13"></span><span class="hs-comment">-- Portability :  non-portable (GHC Extensions)</span><span>
</span><span id="line-14"></span><span class="hs-comment">--</span><span>
</span><span id="line-15"></span><span class="hs-comment">-- References in the 'ST' monad.</span><span>
</span><span id="line-16"></span><span class="hs-comment">--</span><span>
</span><span id="line-17"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-18"></span><span>
</span><span id="line-19"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">GHC.STRef</span><span> </span><span class="hs-special">(</span><span>
</span><span id="line-20"></span><span>        </span><span class="annot"><a href="GHC.STRef.html#STRef"><span class="hs-identifier">STRef</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span>
</span><span id="line-21"></span><span>        </span><span class="annot"><a href="GHC.STRef.html#newSTRef"><span class="hs-identifier">newSTRef</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.STRef.html#readSTRef"><span class="hs-identifier">readSTRef</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.STRef.html#writeSTRef"><span class="hs-identifier">writeSTRef</span></a></span><span>
</span><span id="line-22"></span><span>    </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-23"></span><span>
</span><span id="line-24"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.ST.html"><span class="hs-identifier">GHC.ST</span></a></span><span>
</span><span id="line-25"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Base.html"><span class="hs-identifier">GHC.Base</span></a></span><span>
</span><span id="line-26"></span><span>
</span><span id="line-27"></span><span class="hs-comment">-- $setup</span><span>
</span><span id="line-28"></span><span class="hs-comment">-- import Prelude</span><span>
</span><span id="line-29"></span><span>
</span><span id="line-30"></span><span class="hs-keyword">data</span><span> </span><span id="STRef"><span class="annot"><a href="GHC.STRef.html#STRef"><span class="hs-identifier hs-var">STRef</span></a></span></span><span> </span><span id="local-6989586621679531187"><span class="annot"><a href="#local-6989586621679531187"><span class="hs-identifier hs-type">s</span></a></span></span><span> </span><span id="local-6989586621679531186"><span class="annot"><a href="#local-6989586621679531186"><span class="hs-identifier hs-type">a</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="STRef"><span class="annot"><a href="GHC.STRef.html#STRef"><span class="hs-identifier hs-var">STRef</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Prim.html#MutVar%23"><span class="hs-identifier hs-type">MutVar#</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531187"><span class="hs-identifier hs-type">s</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531186"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-31"></span><span class="hs-comment">-- ^ a value of type @STRef s a@ is a mutable variable in state thread @s@,</span><span>
</span><span id="line-32"></span><span class="hs-comment">-- containing a value of type @a@</span><span>
</span><span id="line-33"></span><span class="hs-comment">--</span><span>
</span><span id="line-34"></span><span class="hs-comment">-- &gt;&gt;&gt; :{</span><span>
</span><span id="line-35"></span><span class="hs-comment">-- runST (do</span><span>
</span><span id="line-36"></span><span class="hs-comment">--     ref &lt;- newSTRef &quot;hello&quot;</span><span>
</span><span id="line-37"></span><span class="hs-comment">--     x &lt;- readSTRef ref</span><span>
</span><span id="line-38"></span><span class="hs-comment">--     writeSTRef ref (x ++ &quot;world&quot;)</span><span>
</span><span id="line-39"></span><span class="hs-comment">--     readSTRef ref )</span><span>
</span><span id="line-40"></span><span class="hs-comment">-- :}</span><span>
</span><span id="line-41"></span><span class="hs-comment">-- &quot;helloworld&quot;</span><span>
</span><span id="line-42"></span><span>
</span><span id="line-43"></span><span class="hs-comment">-- |Build a new 'STRef' in the current state thread</span><span>
</span><span id="line-44"></span><span id="local-6989586621679531199"><span id="local-6989586621679531200"><span class="annot"><a href="GHC.STRef.html#newSTRef"><span class="hs-identifier hs-type">newSTRef</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="#local-6989586621679531200"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.ST.html#ST"><span class="hs-identifier hs-type">ST</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531199"><span class="hs-identifier hs-type">s</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.STRef.html#STRef"><span class="hs-identifier hs-type">STRef</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531199"><span class="hs-identifier hs-type">s</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531200"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span></span><span>
</span><span id="line-45"></span><span id="newSTRef"><span class="annot"><span class="annottext">newSTRef :: forall a s. a -&gt; ST s (STRef s a)
</span><a href="GHC.STRef.html#newSTRef"><span class="hs-identifier hs-var hs-var">newSTRef</span></a></span></span><span> </span><span id="local-6989586621679531168"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679531168"><span class="hs-identifier hs-var">init</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">STRep s (STRef s a) -&gt; ST s (STRef s a)
forall s a. STRep s a -&gt; ST s a
</span><a href="GHC.ST.html#ST"><span class="hs-identifier hs-var">ST</span></a></span><span> </span><span class="annot"><span class="annottext">(STRep s (STRef s a) -&gt; ST s (STRef s a))
-&gt; STRep s (STRef s a) -&gt; ST s (STRef s a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679531166"><span class="annot"><span class="annottext">State# s
</span><a href="#local-6989586621679531166"><span class="hs-identifier hs-var">s1#</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-46"></span><span>    </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">a -&gt; State# s -&gt; (# State# s, MutVar# s a #)
forall a d. a -&gt; State# d -&gt; (# State# d, MutVar# d a #)
</span><a href="../../ghc-prim/src/GHC.Prim.html#newMutVar%23"><span class="hs-identifier hs-var">newMutVar#</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679531168"><span class="hs-identifier hs-var">init</span></a></span><span> </span><span class="annot"><span class="annottext">State# s
</span><a href="#local-6989586621679531166"><span class="hs-identifier hs-var">s1#</span></a></span><span>            </span><span class="hs-keyword">of</span><span> </span><span class="hs-special">{</span><span> </span><span class="hs-special">(#</span><span> </span><span id="local-6989586621679531165"><span class="annot"><span class="annottext">State# s
</span><a href="#local-6989586621679531165"><span class="hs-identifier hs-var">s2#</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679531164"><span class="annot"><span class="annottext">MutVar# s a
</span><a href="#local-6989586621679531164"><span class="hs-identifier hs-var">var#</span></a></span></span><span> </span><span class="hs-special">#)</span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-47"></span><span>    </span><span class="hs-special">(#</span><span> </span><span class="annot"><span class="annottext">State# s
</span><a href="#local-6989586621679531165"><span class="hs-identifier hs-var">s2#</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">MutVar# s a -&gt; STRef s a
forall s a. MutVar# s a -&gt; STRef s a
</span><a href="GHC.STRef.html#STRef"><span class="hs-identifier hs-var">STRef</span></a></span><span> </span><span class="annot"><span class="annottext">MutVar# s a
</span><a href="#local-6989586621679531164"><span class="hs-identifier hs-var">var#</span></a></span><span> </span><span class="hs-special">#)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-48"></span><span>
</span><span id="line-49"></span><span class="hs-comment">-- |Read the value of an 'STRef'</span><span>
</span><span id="line-50"></span><span id="local-6989586621679531184"><span id="local-6989586621679531185"><span class="annot"><a href="GHC.STRef.html#readSTRef"><span class="hs-identifier hs-type">readSTRef</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.STRef.html#STRef"><span class="hs-identifier hs-type">STRef</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531185"><span class="hs-identifier hs-type">s</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531184"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.ST.html#ST"><span class="hs-identifier hs-type">ST</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531185"><span class="hs-identifier hs-type">s</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531184"><span class="hs-identifier hs-type">a</span></a></span></span></span><span>
</span><span id="line-51"></span><span id="readSTRef"><span class="annot"><span class="annottext">readSTRef :: forall s a. STRef s a -&gt; ST s a
</span><a href="GHC.STRef.html#readSTRef"><span class="hs-identifier hs-var hs-var">readSTRef</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.STRef.html#STRef"><span class="hs-identifier hs-type">STRef</span></a></span><span> </span><span id="local-6989586621679531163"><span class="annot"><span class="annottext">MutVar# s a
</span><a href="#local-6989586621679531163"><span class="hs-identifier hs-var">var#</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">STRep s a -&gt; ST s a
forall s a. STRep s a -&gt; ST s a
</span><a href="GHC.ST.html#ST"><span class="hs-identifier hs-var">ST</span></a></span><span> </span><span class="annot"><span class="annottext">(STRep s a -&gt; ST s a) -&gt; STRep s a -&gt; ST s a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679531162"><span class="annot"><span class="annottext">State# s
</span><a href="#local-6989586621679531162"><span class="hs-identifier hs-var">s1#</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">MutVar# s a -&gt; STRep s a
forall d a. MutVar# d a -&gt; State# d -&gt; (# State# d, a #)
</span><a href="../../ghc-prim/src/GHC.Prim.html#readMutVar%23"><span class="hs-identifier hs-var">readMutVar#</span></a></span><span> </span><span class="annot"><span class="annottext">MutVar# s a
</span><a href="#local-6989586621679531163"><span class="hs-identifier hs-var">var#</span></a></span><span> </span><span class="annot"><span class="annottext">State# s
</span><a href="#local-6989586621679531162"><span class="hs-identifier hs-var">s1#</span></a></span><span>
</span><span id="line-52"></span><span>
</span><span id="line-53"></span><span class="hs-comment">-- |Write a new value into an 'STRef'</span><span>
</span><span id="line-54"></span><span id="local-6989586621679531180"><span id="local-6989586621679531181"><span class="annot"><a href="GHC.STRef.html#writeSTRef"><span class="hs-identifier hs-type">writeSTRef</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.STRef.html#STRef"><span class="hs-identifier hs-type">STRef</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531181"><span class="hs-identifier hs-type">s</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531180"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679531180"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.ST.html#ST"><span class="hs-identifier hs-type">ST</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531181"><span class="hs-identifier hs-type">s</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span></span></span><span>
</span><span id="line-55"></span><span id="writeSTRef"><span class="annot"><span class="annottext">writeSTRef :: forall s a. STRef s a -&gt; a -&gt; ST s ()
</span><a href="GHC.STRef.html#writeSTRef"><span class="hs-identifier hs-var hs-var">writeSTRef</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.STRef.html#STRef"><span class="hs-identifier hs-type">STRef</span></a></span><span> </span><span id="local-6989586621679531161"><span class="annot"><span class="annottext">MutVar# s a
</span><a href="#local-6989586621679531161"><span class="hs-identifier hs-var">var#</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679531160"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679531160"><span class="hs-identifier hs-var">val</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">STRep s () -&gt; ST s ()
forall s a. STRep s a -&gt; ST s a
</span><a href="GHC.ST.html#ST"><span class="hs-identifier hs-var">ST</span></a></span><span> </span><span class="annot"><span class="annottext">(STRep s () -&gt; ST s ()) -&gt; STRep s () -&gt; ST s ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679531159"><span class="annot"><span class="annottext">State# s
</span><a href="#local-6989586621679531159"><span class="hs-identifier hs-var">s1#</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-56"></span><span>    </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">MutVar# s a -&gt; a -&gt; State# s -&gt; State# s
forall d a. MutVar# d a -&gt; a -&gt; State# d -&gt; State# d
</span><a href="../../ghc-prim/src/GHC.Prim.html#writeMutVar%23"><span class="hs-identifier hs-var">writeMutVar#</span></a></span><span> </span><span class="annot"><span class="annottext">MutVar# s a
</span><a href="#local-6989586621679531161"><span class="hs-identifier hs-var">var#</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679531160"><span class="hs-identifier hs-var">val</span></a></span><span> </span><span class="annot"><span class="annottext">State# s
</span><a href="#local-6989586621679531159"><span class="hs-identifier hs-var">s1#</span></a></span><span>      </span><span class="hs-keyword">of</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621679531158"><span class="annot"><span class="annottext">State# s
</span><a href="#local-6989586621679531158"><span class="hs-identifier hs-var">s2#</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-57"></span><span>    </span><span class="hs-special">(#</span><span> </span><span class="annot"><span class="annottext">State# s
</span><a href="#local-6989586621679531158"><span class="hs-identifier hs-var">s2#</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-special">#)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-58"></span><span>
</span><span id="line-59"></span><span class="hs-comment">-- | Pointer equality.</span><span>
</span><span id="line-60"></span><span class="hs-comment">--</span><span>
</span><span id="line-61"></span><span class="hs-comment">-- @since 2.01</span><span>
</span><span id="line-62"></span><span id="local-6989586621679531175"><span id="local-6989586621679531176"><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621679531155"><span class="annot"><a href="../../ghc-prim/src/GHC.Classes.html#Eq"><span class="hs-identifier hs-type">Eq</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.STRef.html#STRef"><span class="hs-identifier hs-type">STRef</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531176"><span class="hs-identifier hs-type">s</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531175"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-63"></span><span>    </span><span class="annot"><a href="GHC.STRef.html#STRef"><span class="hs-identifier hs-type">STRef</span></a></span><span> </span><span id="local-6989586621679531153"><span class="annot"><span class="annottext">MutVar# s a
</span><a href="#local-6989586621679531153"><span class="hs-identifier hs-var">v1#</span></a></span></span><span> </span><span id="local-6989586621679531152"><span class="annot"><span class="annottext">== :: STRef s a -&gt; STRef s a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var hs-var hs-var hs-var">==</span></a></span></span><span> </span><span class="annot"><a href="GHC.STRef.html#STRef"><span class="hs-identifier hs-type">STRef</span></a></span><span> </span><span id="local-6989586621679531151"><span class="annot"><span class="annottext">MutVar# s a
</span><a href="#local-6989586621679531151"><span class="hs-identifier hs-var">v2#</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int# -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#isTrue%23"><span class="hs-identifier hs-var">isTrue#</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">MutVar# s a -&gt; MutVar# s a -&gt; Int#
forall d a. MutVar# d a -&gt; MutVar# d a -&gt; Int#
</span><a href="../../ghc-prim/src/GHC.Prim.html#sameMutVar%23"><span class="hs-identifier hs-var">sameMutVar#</span></a></span><span> </span><span class="annot"><span class="annottext">MutVar# s a
</span><a href="#local-6989586621679531153"><span class="hs-identifier hs-var">v1#</span></a></span><span> </span><span class="annot"><span class="annottext">MutVar# s a
</span><a href="#local-6989586621679531151"><span class="hs-identifier hs-var">v2#</span></a></span><span class="hs-special">)</span></span></span><span>
</span><span id="line-64"></span></pre></body></html>